// MainObject.cpp : Implementation of CMainObject
#include "stdafx.h"
#include "Atlplugin.h"
#include "MainObject.h"

/////////////////////////////////////////////////////////////////////////////
// CMainObject


STDMETHODIMP CMainObject::Init(LPDISPATCH objApp, VARIANT_BOOL *pbResult)
{
	// TODO: Add your implementation code here
	*pbResult = VARIANT_TRUE;
	return S_OK;
}

STDMETHODIMP CMainObject::get_MenuName(BSTR *pVal)
{
	CComBSTR bsName("Atl Test!");
	*pVal = bsName.Detach();
	return S_OK;
}

STDMETHODIMP CMainObject::OnMenu()
{
	MessageBox(GetActiveWindow(), "On Atl Test!", "atlplugin", MB_OK|MB_SETFOREGROUND);
	return S_OK;
}

STDMETHODIMP CMainObject::get_MenuIcon(IDispatch **pVal)
{
	IDispatch* pDisp = 0;
 
	PICTDESC pictDesc;
	memset(&pictDesc, 0, sizeof(pictDesc));
	pictDesc.cbSizeofstruct = sizeof(pictDesc);
	pictDesc.icon.hicon = LoadIcon(_Module.m_hInst, MAKEINTRESOURCE(IDI_ICON));
	pictDesc.picType = PICTYPE_ICON;
	HRESULT hr = OleCreatePictureIndirect(&pictDesc, IID_IDispatch, TRUE, (void**)pVal);
	if(FAILED(hr))
	{
		MessageBox(0, "Failed to create stdpicture", NULL, 0);
	}
//	
//	UpdateData(TRUE);
//	switch(m_nPicture)
//	{
//	case 0:
//		{
//			pictDesc.bmp.hbitmap = m_ctlYellow.GetBitmap();
//			pictDesc.picType = PICTYPE_BITMAP;
//			
//			HRESULT hr;
//			hr = OleCreatePictureIndirect(&pictDesc,
//				IID_IDispatch, 
//				FALSE, 
//				(void**)&pDisp);
//			if(SUCCEEDED(hr))
//			{
//				ExamineIPicture(pDisp);
//				
//				m_flexgrid.SetRefCellPicture(pDisp);
//				pDisp->Release();
//			} else
//			{
//				AfxMessageBox("Couldn't create the/
//					Picture interface");
//			}
//		}
//		break;
//	case 1:
//		{
//			// Similar treatment for this bitmap
//		}
//		break;
//	case 2:
//		{
//			// Similar treatment for this bitmap
//		}
//		break;
//	default :
//		break;
//	}
//	
	return S_OK;
}
